package com.xiaoxin.experience.util;

import java.util.concurrent.TimeUnit;

/**
 * @author xiaoxin
 */
public class TimeUtil
{
    private TimeUtil(){}

    public static String getHumanTime(long millis)
    {
        if (millis < 1000)
        {
            return millis + "毫秒";
        }
        TimeUnit milliseconds = TimeUnit.MILLISECONDS;
        long seconds = milliseconds.toSeconds(millis);
        if (seconds < 60)
        {
            return seconds + "秒";
        }
        long minutes = milliseconds.toMinutes(millis);
        if (minutes < 60)
        {
            return minutes + "分" + (seconds%60) + "秒";
        }
        long hours = milliseconds.toHours(millis);
        if (hours < 24)
        {
            return hours + "时" + (minutes%60) + "分" + (seconds%60) + "秒";
        }
        long days = milliseconds.toDays(millis);
        if (days < 365)
        {
            return days + "天" + (hours%24) + "时" + (minutes%60) + "分" + (seconds%60) + "秒";
        }
        return (days/365) + "年" + (days%365) + "天" + (hours%24) + "时" + (minutes%60) + "分" + (seconds%60) + "秒";
    }
}
